package com.orisper.esb.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.orisper.utils.QiniuUploadFile;
import com.orisper.utils.UploadUtils;

import aos.framework.core.asset.WebCxt;
import aos.framework.core.typewrap.Dto;
import aos.framework.core.typewrap.Dtos;
import aos.framework.core.utils.AOSJson;

/**
 * api接口
 * 
 * @author deng
 *
 */
@Controller
@RequestMapping(value = "api/common")
public class ApiCommonController {
	
	/**
	 * 上传图片
	 * 
	 */
	@RequestMapping(value = "uploadPic")
	public void register(@RequestParam(value = "uploadPic", required = true) MultipartFile uploadPic,HttpServletRequest request, HttpServletResponse response) {
		String result="";
		Dto oDto=Dtos.newOutDto();
		try {
			//result=UploadUtils.save(uploadPic, "/upload");
			result=QiniuUploadFile.upload(uploadPic);
			oDto.put("url", result);
			oDto.setAppMsg("图片上传成功！！");
			oDto.put("success", true);
		} catch (Exception e) {
			oDto.setAppCode("-1");
			oDto.setAppMsg(e.getMessage());
		}finally{
			WebCxt.write(response,AOSJson.toJson(oDto));
		}

	}
	
}
